package com.cookman.gameobjects.decks;

import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.cookman.actions.AcceptAction;
import com.cookman.actions.Action;
import com.cookman.actions.CancelAction;
import com.cookman.gameobjects.ActionButtons.AcceptActionActor;
import com.cookman.gameobjects.ActionButtons.ActionActor;
import com.cookman.gameobjects.ActionButtons.CancelActionActor;
import com.cookman.gameobjects.ActionButtons.listeners.ExecuteActionListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Cookman on 16.09.14.
 */
public class ActionDeckActor extends Group {

    private List<Action> actions;
    private List<ActionActor> actionActors;

    private float scale = 0.5f;

    public ActionDeckActor() {
        super();
    }

    public void setActions(List<Action> actions) {
        clearChildren();
        this.actions = actions;
        float xPos = 0;
        actionActors=new ArrayList<>();
        for (Action action : actions) {
            ActionActor actionActor;
            if (action instanceof CancelAction) {
                actionActor = new CancelActionActor(action);
            } else if (action instanceof AcceptAction) {
                actionActor = new AcceptActionActor(action);
            } else {
                actionActor = new ActionActor(action);
            }
            actionActor.addListener(new ExecuteActionListener());
            actionActor.setX(xPos);
            addActor(actionActor);
            actionActor.setBounds(xPos, 0, scale, scale);
            xPos += scale + 0.2f;
            actionActors.add(actionActor);
        }
    }

    public void renderShape(ShapeRenderer renderer) {
        if (actions != null)
            for (ActionActor actionActor : actionActors) {
                actionActor.renderShape(renderer);
            }
    }

}
